home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
network
/
ka9q
/
nhclb120.zoo
/
nrcmd.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-06-18
|
26KB
|
1,280 lines
/* net/rom user command processing
* Copyright 1989 by Daniel M. Frank, W9NK. Permission granted for
* non-commercial distribution only.
*/
#include <stdio.h>
#include "global.h"
#include "config.h"
#include "mbuf.h"
#include "ax25.h"
#include "timer.h"
#include "iface.h"
#include "lapb.h"
#include "netrom.h"
#include "nr4.h"
#include "netuser.h"
#include "tcp.h"
#include "ftp.h"
#include "telnet.h"
#include "finger.h"
#include "ax_mbx.h"
#include "cmdparse.h"
#include "session.h"
#include <ctype.h>
#ifdef UNIX
#undef toupper
#undef tolower
#include <memory.h>
#include <string.h>
#endif
#undef NRDEBUG
static int donodetick();
static int doobsotick();
static donfdump();
static void donrdump();
long atol();
extern struct session *current;
char *Nr4states[] = {
"Disconnected",
"Conn Pending",
"Connected",
"Disc Pending"
} ;
char *Nr4reasons[] = {
"Normal",
"By Peer",
"Timeout",
"Reset",
"Refused"
} ;
static int dointerface(), dobcnodes(), donodetimer(), donrroute(),
donrttl(), doobsotimer(), donodefilter(), donrverbose(),
donrconnect(), donrreset(), donrwindow(), donrirtt(),
donracktime(), donrqlimit(), donrchoketime(), donrretries(),
donrstatus(), donrkick() ;
static struct cmds nrcmds[] = {
"acktime", donracktime, 0, NULLCHAR, NULLCHAR,
"bcnodes", dobcnodes, 2, "netrom bcnodes <interface>", NULLCHAR,
/* Put connect before choketime to make it the default expansion of 'c' */
"connect", donrconnect,2, "netrom connect <node>", NULLCHAR,
"choketime", donrchoketime, 0, NULLCHAR, NULLCHAR,
"interface", dointerface, 4,
"netrom interface <interface> <alias> <quality>", NULLCHAR,
"irtt", donrirtt, 0, NULLCHAR, NULLCHAR,
"kick", donrkick, 2, "netrom kick <&nrcb>", NULLCHAR,
"nodefilter", donodefilter, 0, NULLCHAR, NULLCHAR,
"nodetimer", donodetimer, 0, NULLCHAR, NULLCHAR,
"obsotimer", doobsotimer, 0, NULLCHAR, NULLCHAR,
"qlimit", donrqlimit, 0, NULLCHAR, NULLCHAR,
"reset", donrreset, 2, "netrom reset <&nrcb>", NULLCHAR,
"retries", donrretries,0, NULLCHAR, NULLCHAR,
"route", donrroute, 0, NULLCHAR, NULLCHAR,
"status", donrstatus, 0, NULLCHAR, NULLCHAR,
"ttl", donrttl, 0, NULLCHAR, NULLCHAR,
"verbose", donrverbose,0, NULLCHAR, NULLCHAR,
"window", donrwindow, 0, NULLCHAR, NULLCHAR,
NULLCHAR, NULLFP, 0,
"netrom subcommands: acktime bcnodes connect choketime interface irtt kick\n nodetimer nodefilter obsotimer qlimit reset retries route\n status ttl verbose window",
NULLCHAR
} ;
static struct timer nodetimer ; /* timer for nodes broadcasts */
static struct timer obsotimer ; /* timer for aging routes */
/* Command multiplexer */
donetrom(argc,argv)
int argc ;
char *argv[] ;
{
return subcmd(nrcmds,argc,argv) ;
}
static int dorouteadd(), doroutedrop(), doroutedump(), dorouteinfo() ;
static struct cmds routecmds[] = {
"add", dorouteadd, 6,
"netrom route add <alias> <destination> <interface> <quality> <neighbor>",
"add failed",
"drop", doroutedrop, 4,
"netrom route drop <destination> <neighbor> <interface>",
"drop failed",
"info", dorouteinfo, 2,
"netrom route info <destination>", NULLCHAR,
NULLCHAR, NULLFP, 0,
"netrom route subcommands: add drop info",
NULLCHAR
} ;
/* Route command multiplexer */
static
donrroute(argc, argv)
int argc ;
char *argv[] ;
{
if (argc < 2) {
doroutedump() ;
return 0 ;
}
return subcmd(routecmds,argc,argv) ;
}
/* Dump a list of known routes */
static
doroutedump()
{
register struct nrroute_tab *rp ;
register int i, column ;
char buf[32] ;
char *cp ;
int count = 0;
column = 1 ;
for (i = 0 ; i < NRNUMCHAINS ; i++)
for (rp = nrroute_tab[i] ; rp != NULLNRRTAB ; rp = rp->next) {
strcpy(buf,rp->alias) ;
/* remove trailing spaces */
if ((cp = index(buf,' ')) == NULLCHAR)
cp = &buf[strlen(buf)] ;
if (cp != buf) /* don't include colon for null alias */
*cp++ = ':' ;
pax25(cp,&rp->call) ;
printf("%-16s ",buf) ;
count++;
if (column++ == 4) {
printf("\n") ;
column = 1 ;
}
}
if (column != 1)
printf("\n") ;
printf("Total station count = %d\n",count);
return 0 ;
}
/* print detailed information on an individual route */
/*ARGSUSED*/
static int
dorouteinfo(argc,argv)
int argc ;
char *argv[] ;
{
register struct nrroute_tab *rp ;
register struct nr_bind *bp ;
register struct nrnbr_tab *np ;
struct ax25_addr dest ;
char neighbor[60] ;
if (setcall(&dest,argv[1]) == -1) {
printf ("bad destination name\n") ;
return -1 ;
}
if ((rp = find_nrroute(&dest)) == NULLNRRTAB) {
printf("no such route\n") ;
return -1 ;
}
for (bp = rp->routes ; bp != NULLNRBIND ; bp = bp->next) {
np = bp->via ;
psax25(neighbor,np->call) ;
printf("%1s %3d %3d %-8s %s\n",
(bp->flags & NRB_PERMANENT ? "P" :
bp->flags & NRB_RECORDED ? "R" : " "),
bp->quality,bp->obsocnt,
nrifaces[np->interface].interface->name,
neighbor) ;
}
return 0 ;
}
/* convert a null-terminated alias name to a blank-filled, upcased */
/* version. Return -1 on failure. */
static int
putalias(to,from,complain)
register char *to, *from ;
int complain ;
{
int len, i ;
if ((len = strlen(from)) > ALEN) {
if (complain)
printf ("alias too long - six characters max\n") ;
return -1 ;
}
for (i = 0 ; i < ALEN ; i++) {
if (i < len) {
if (islower(*from))
*to++ = toupper(*from++) ;
else
*to++ = *from++ ;
}
else
*to++ = ' ' ;
}
*to = '\0' ;
return 0 ;
}
/* Add a route */
static int
dorouteadd(argc, argv)
int argc ;
char *argv[] ;
{
char alias[7] ;
struct ax25_addr dest ;
unsigned quality ;
char neighbor[AXALEN * 3] ;
register int i ;
int naddr ;
/* format alias (putalias prints error message if necessary) */
if (putalias(alias,argv[1],1) == -1)
return -1 ;
/* format destination callsign */
if (setcall(&dest,argv[2]) == -1) {
printf("bad destination callsign\n") ;
return -1 ;
}
/* find interface */
for (i = 0 ; i < nr_numiface ; i++)
if (!strcmp(nrifaces[i].interface->name,argv[3]))
break ;
if (i == nr_numiface) {
printf("Interface \"%s\" not found\n",argv[3]) ;
return -1 ;
}
/* get and check quality value */
if ((quality = atoi(argv[4])) > 255) {
printf("maximum route quality is 255\n") ;
return -1 ;
}
/* make sure no more than 2 digis */
naddr = argc - 5 ;
if (naddr > 3) {
printf("no more than 2 digipeaters for a net/rom neighbor\n") ;
return -1 ;
}
/* format neighbor address string */
setpath(neighbor,&argv[5],naddr) ;
return nr_routeadd(alias,&dest,(unsigned)i,quality,neighbor,1,0) ;
}
/* drop a route */
/*ARGSUSED*/
static
doroutedrop(argc,argv)
int argc ;
char *argv[] ;
{
struct ax25_addr dest, neighbor ;
register int i ;
/* format destination and neighbor callsigns */
if (setcall(&dest,argv[1]) == -1) {
printf("bad destination callsign\n") ;
return -1 ;
}
if (setcall(&neighbor,argv[2]) == -1) {
printf("bad neighbor callsign\n") ;
return -1 ;
}
/* find interface */
for (i = 0 ; i < nr_numiface ; i++)
if (!strcmp(nrifaces[i].interface->name,argv[3]))
break ;
if (i == nr_numiface) {
printf("Interface \"%s\" not found\n",argv[3]) ;
return -1 ;
}
return nr_routedrop(&dest,&neighbor,(unsigned)i) ;
}
/* make an interface available to net/rom */
/*ARGSUSED*/
static int
dointerface(argc,argv)
int argc ;
char *argv[] ;
{
int i ;
register struct interface *ifp ;
extern struct interface *ifaces ;
if (nr_interface == NULLIF) {
printf("Attach netrom interface first\n") ;
return 1 ;
}
if (nr_numiface >= NRNUMIFACE) {
printf("Only %d net/rom interfaces available\n",NRNUMIFACE) ;
return 1 ;
}
for(ifp=ifaces;ifp != NULLIF;ifp = ifp->next){
if(strcmp(argv[1],ifp->name) == 0)
break;
}
if(ifp == NULLIF){
printf("Interface \"%s\" unknown\n",argv[1]);
return 1;
}
for (i = 0 ; i < nr_numiface ; i++)
if (nrifaces[i].interface == ifp) {
printf("Interface \"%s\" is already registered\n",argv[1]) ;
return 1 ;
}
nrifaces[nr_numiface].interface = ifp ;
if (putalias(nrifaces[nr_numiface].alias,argv[2],1) == -1)
return 1 ;
if ((nrifaces[nr_numiface].quality = atoi(argv[3])) > 255) {
printf("Q